import smtplib
import schedule
import time
from email.mime.text import MIMEText
from email.header import Header

print("邮件定时开始启动")
# 设置发件人邮箱地址和密码
sender_email = "1214392081@qq.com"
sender_password = "sujjypplprbofffd"

# 设置收件人邮箱地址
recipient_email = "liurukai@dingtalk.com"
#recipient_email = "kkk9789@dingtalk.com"

# 读取文件内容作为邮件内容
def read_file_and_send():
    with open("C:\\Users\\sanye\\Desktop\\工作记录\\周报.md", "r", encoding="utf-8") as file: #修改成自己的文件路径
        body = file.read()

    # 创建邮件内容
    subject = "周报（李庆）"
    msg = MIMEText(body, 'plain', 'utf-8')
    msg['From'] = sender_email  # 发件人邮箱地址
    msg['To'] = recipient_email
    msg['Subject'] = Header(subject, 'utf-8')

    # 连接到QQ邮箱的SMTP服务器
    with smtplib.SMTP_SSL("smtp.qq.com", 465) as smtp:
        smtp.login(sender_email, sender_password)  # 登录到QQ邮箱

        # 发送邮件
        smtp.sendmail(sender_email, recipient_email, msg.as_string())

    print("邮件发送成功！")

read_file_and_send()

def append_weekly_report(source_file, target_file):
    # 打开源文件并读取内容
    with open(source_file, "r", encoding="utf-8") as source:
        source_content = source.read()

    # 打开目标文件并将内容追加到最后
    with open(target_file, "a", encoding="utf-8") as target:
        target.write("\n")  # 添加一个空行
        target.write(source_content)

    # 清空源文件内容
    with open(source_file, "w", encoding="utf-8") as source:
        source.write("")

# 调用函数，将周报.md的内容写入到2024周报.md文件的最下面，并清空周报.md文件内容
append_weekly_report(r"C:\Users\sanye\Desktop\工作记录\周报.md", r"C:\Users\sanye\Desktop\工作记录\2024周报.md")


